package com.mengxuegu.springboot.controller;

import com.mengxuegu.springboot.entities.*;
import com.mengxuegu.springboot.service.IUserDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class UserDetailController {
    @Autowired
    private IUserDetailService userDetailService;

    @GetMapping("/userDetail")
    public UserDetail getUserDetail(Integer id) {
        UserDetail userDetail = userDetailService.getById(id);
        return userDetail;
    }

    /**
     * 测试UserWork
     * @return
     */
    @PostMapping("/userDetail")
    public UserDetail save() {
        UserDetail userDetail = new UserDetail();
        UserWork userWork = new UserWork();
        userWork.setSalary(33);
        userDetail.setUserWork(userWork);
        List<String> addr = new ArrayList<>();
        addr.add("shanghai");
        addr.add("beijing");
        userDetail.setAddr(addr);
        userDetailService.save(userDetail);
        return userDetail;
    }

    /**
     * 测试TableField
     * @return
     */
    @PostMapping("/userDetail2")
    public UserDetail save2() {
        UserDetail userDetail = new UserDetail();

        YelloUserFeature userFeature = new YelloUserFeature();
        userFeature.setSkin("yello");
        userDetail.setUserFeature(userFeature);

        YelloUserBehavior userBehavior = new YelloUserBehavior();
        userBehavior.setJump("jump");
        userBehavior.setRun("run");
        userBehavior.setUserFeature(userFeature);
        userDetail.setUserBehavior(userBehavior);

        userDetailService.save(userDetail);
        UserDetail userDetailSel = userDetailService.getById(userDetail.getId());
        return userDetailSel;
    }

    /**
     * 测试TableField
     * @return
     */
    @PostMapping("/userDetail3")
    public UserDetail save3() {
        UserDetail userDetail = new UserDetail();

        YelloUserBehavior userBehavior = new YelloUserBehavior();
//        userBehavior.setJump("jump");
        userBehavior.setRun("run");
        OtherInfo otherInfo = new OtherInfo();
        otherInfo.setUserBehavior(userBehavior);
        userDetail.setOtherInfo(otherInfo);

        userDetailService.save(userDetail);
        UserDetail userDetailSel = userDetailService.getById(userDetail.getId());
        return userDetailSel;
    }
}
